/**
 * Created by Administrator on 2016/11/26.
 */
class FashionTools {

    //自动出牌
    static autoPush() {
        if (GSConfig.auto) {
            let pai = GSData.i.getCatchPai(1);
            gameManager.socketManager.send(4, pai);
        }
    }

    //自动过
    static autoPass() {
        if (GSConfig.auto) {
            gameManager.socketManager.send(15, { action: 0, pai: [] });
            GSController.i.hideFuncSelectMenu();

            let pais = PublicVal.i.getHandPais(1);
            if (pais) {
                if (GSConfig.allowLens(pais.length)) {
                    FashionTools.autoPush();
                }
            }
        }
    }

    //数组排序
    static sortPai(list: any[]) {
        if (!list) return;

        list.sort((a: any, b: any) => {
            let ai = a.type * 10 + a.number;
            let bi = b.type * 10 + b.number;

            if (a.type == game.roomQue[1]) {
                ai += 100;
            }

            if (b.type == game.roomQue[1]) {
                bi += 100;
            }

            return ai > bi ? 1 : -1;
        });
    }

    //数组移除元素
    static removePai(list: any[], pai: any, reverse: boolean = true) {
        if (!list || !pai) return;

        let index: number = -1;
        if (reverse) {
            for (let i: number = list.length; i > 0; i--) {
                if (pai.type == list[i - 1].type && pai.number == list[i - 1].number) {
                    index = i - 1;
                    break;
                }
            }
        }
        else {
            for (let i: number = 0; i < list.length; i++) {
                if (pai.type == list[i].type && pai.number == list[i].number) {
                    index = i;
                    break;
                }
            }
        }

        if (index != -1) list.splice(index, 1);
    }


    /*
       获取代开的房间信息
    */
    static getDaikaiRoomDes(data: any) {

        var round = data.round;
        var round_type = data.round_type;
        var rules = data.rules;
        //var fengding = data.fengding;
        //var gang = GSConfig.createProDB.gang[data.gang];
        return round + FashionTools.getRoundTypeStr(round_type) + " "
            //+ gang
            + game.ruleTexts(rules);
        //+ GSConfig.fengdingDB[fengding] + FashionTools.formatRules(rules);

    }
    /*

     */
    static getRoundTypeStr(round_type: number) {

        return round_type == 0 ? "圈" : "把";

    }


    static indexOfPai(list: any[], pai: any): number {
        let idx: number = -1;
        list.some((_pai, i) => {
            let flag: boolean = pai.type == _pai.type && pai.number == _pai.number;
            if (flag) {
                idx = i;
            }
            return flag;
        });
        return idx;
    }

}